package lib.bone.admin.controller.nepu;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lib.bone.audit.workload.service.NepuWorkloadService;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.nepudata.domain.dto.overtime.OvertimeProjectAddDTO;
import lib.bone.nepudata.domain.entity.NepuOvertimeProject;
import lib.bone.nepudata.domain.entity.NepuSubject;
import lib.bone.nepudata.service.NepuOvertimeProjectService;
import lib.bone.nepudata.service.NepuPaperService;
import lib.bone.nepudata.service.impl.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("nepu")
@Api(tags = "超期管理")
public class OvertimeProjectController {

    @Autowired
    NepuOvertimeProjectService service;

    @Autowired
    NepuWorkloadService workloadService;

    @PostMapping("overtime")
    @ApiOperation(value = "超期记录新增")
    public ResponseDTO<Object> overTimeCreate(@RequestBody @Validated OvertimeProjectAddDTO overtimeProjectAddDTO){
        NepuOvertimeProject nepuOvertimeProject = new NepuOvertimeProject();
        BeanUtil.copyProperties(overtimeProjectAddDTO,nepuOvertimeProject, CopyOptions.create().setIgnoreError(true).setIgnoreNullValue(true));
        return ResponseDTO.succData(
                service.saveOne(nepuOvertimeProject)
        );
    }

    @GetMapping("overtime/{linkId}")
    @ApiOperation(value = "超期记录查询(linkId)")
    public ResponseDTO<Object> getOverTimeProject(@PathVariable("linkId") String linkId){
        return ResponseDTO.succData(
                service.getByLinkId(linkId)
        );
    }

    @GetMapping("overtime/projects")
    @ApiOperation(value = "超期项目工作量查询")
    public ResponseDTO<Object> getOvertimeProjects(){
        List<NepuOvertimeProject> projects = service.getAll();
        List<String> linkIds = projects.stream().map(NepuOvertimeProject::getLinkId).collect(Collectors.toList());
        log.info("超期有{}",linkIds.size());
        return ResponseDTO.succData(
                workloadService.getByLinkIds(linkIds)
        );
    }


    @Autowired
    NepuPaperService paperService;

    @GetMapping("overtime/papers")
    @ApiOperation(value = "超期论文查询")
    public ResponseDTO<Object> getOvertimePapers(){
        List<NepuOvertimeProject> projects = service.getAll();
        List<String> linkIds = projects.stream().map(NepuOvertimeProject::getLinkId).collect(Collectors.toList());
        log.info("超期有{}",linkIds.size());
        return ResponseDTO.succData(
                paperService.getByIds(linkIds)
        );
    }

    @Autowired
    NepuTopicServiceImpl topicService;

    @GetMapping("overtime/topics")
    @ApiOperation(value = "超期纵向查询")
    public ResponseDTO<Object> getOvertimeTopics(){
        List<NepuOvertimeProject> projects = service.getAll();
        List<String> linkIds = projects.stream().map(NepuOvertimeProject::getLinkId).collect(Collectors.toList());
        log.info("超期有{}",linkIds.size());
        return ResponseDTO.succData(
                topicService.getByIdIn(linkIds)
        );

    }

    @Autowired
    NepuSubjectServiceImpl nepuSubjectService;

    @GetMapping("overtime/subjects")
    @ApiOperation(value = "超期横向查询")
    public ResponseDTO<Object> getOvertimeSubjects(){
        List<NepuOvertimeProject> projects = service.getAll();
        List<String> linkIds = projects.stream().map(NepuOvertimeProject::getLinkId).collect(Collectors.toList());
        log.info("超期有{}",linkIds.size());
        return ResponseDTO.succData(
                nepuSubjectService.getByIdIn(linkIds)
        );

    }

    @Autowired
    NepuAwardServiceImpl nepuAwardService;

    @GetMapping("overtime/awards")
    @ApiOperation(value = "超期获奖查询")
    public ResponseDTO<Object> getOvertimeAwards(){
        List<NepuOvertimeProject> projects = service.getAll();
        List<String> linkIds = projects.stream().map(NepuOvertimeProject::getLinkId).collect(Collectors.toList());
        log.info("超期有{}",linkIds.size());
        return ResponseDTO.succData(
                nepuAwardService.getByIdIn(linkIds)
        );

    }

    @Autowired
    NepuBookServiceImpl nepuBookService;

    @GetMapping("overtime/books")
    @ApiOperation(value = "超期著作查询")
    public ResponseDTO<Object> getOvertimeBooks(){
        List<NepuOvertimeProject> projects = service.getAll();
        List<String> linkIds = projects.stream().map(NepuOvertimeProject::getLinkId).collect(Collectors.toList());
        log.info("超期有{}",linkIds.size());
        return ResponseDTO.succData(
                nepuBookService.getByIdIn(linkIds)
        );

    }

    @Autowired
    NepuThinkTankServiceImpl nepuThinkTankService;

    @GetMapping("overtime/thinktanks")
    @ApiOperation(value = "超期智库查询")
    public ResponseDTO<Object> getOvertimeThinkTanks(){
        List<NepuOvertimeProject> projects = service.getAll();
        List<String> linkIds = projects.stream().map(NepuOvertimeProject::getLinkId).collect(Collectors.toList());
        log.info("超期有{}",linkIds.size());
        return ResponseDTO.succData(
                nepuThinkTankService.getByIdIn(linkIds)
        );

    }

    @Autowired
    NepuPropertyServiceImpl nepuPropertyService;

    @GetMapping("overtime/property")
    @ApiOperation(value = "超期知识产权查询")
    public ResponseDTO<Object> getOvertimePropertys(){
        List<NepuOvertimeProject> projects = service.getAll();
        List<String> linkIds = projects.stream().map(NepuOvertimeProject::getLinkId).collect(Collectors.toList());
        log.info("超期有{}",linkIds.size());
        return ResponseDTO.succData(
                nepuPropertyService.getByIdIn(linkIds)
        );

    }


}
